$(document).ready(function () {
    var dataPeriod = $('#report_content').attr('data-period');

    $('.btn-search').click(function () {
        var $innerSelect = $('#inner-select');
        var dataType = $innerSelect.attr('data-type');
        var dataId = $innerSelect.attr('data-id');
        var dataPeriod = $('#report_content').attr('data-period');

        $('#report_content').html('');
        showLoadingAnimation();

        getReport(dataType, dataId, dataPeriod);
    });

    $('.loading').hide();
    showLoadingAnimation(true);

    getReport('school', '', dataPeriod);
});

function getReport(type, id, period) {
    var request = new Request('/leader/attendance/report', {
        type: type,
        id: id,
        period: period
    });

    loadPage('#report_content', request.url, function () {
        $('.loading').hide();
    });
}

function innerSelectClicked(event) {
    var $select = $(event.currentTarget);
    var $innerSelect = $('#inner-select');

    var dataType = $select.attr('data-type');
    var dataId = $select.attr('data-id');

    $innerSelect.html($select.html());
    $innerSelect.attr('data-type', dataType);
    $innerSelect.attr('data-id', dataId);
}

function showLoadingAnimation(animate) {
    var loading = $('.loading');
    loading.show();
    if (animate) {
        loading.shCircleLoader();
    }
}